package com.yunkaweilai.android.activity.login;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.classic.common.MultipleStatusView;
import com.google.gson.Gson;
import com.yunkaweilai.android.R;
import com.yunkaweilai.android.base.BaseActivity;
import com.yunkaweilai.android.constants.Api;
import com.yunkaweilai.android.model.login.IndustryModel;
import com.yunkaweilai.android.model.login.ShiftModel;
import com.yunkaweilai.android.model.operation.EmployeeListBean;
import com.yunkaweilai.android.net.HttpRequest;
import com.yunkaweilai.android.net.PostProcess;
import com.yunkaweilai.android.utils.TitleBuilder;
import com.yunkaweilai.android.utils.Utils;
import com.zhy.adapter.abslistview.CommonAdapter;
import com.zhy.adapter.abslistview.ViewHolder;

import java.io.Serializable;
import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 交班人列表
 * Created by Administrator on 2017/7/24.
 */

public class ShiftManListActivity extends BaseActivity {

    @BindView(R.id.id_listview)
    ListView idListview;
    @BindView(R.id.id_multipleStatusView)
    MultipleStatusView idMultipleStatusView;
    public static final String SHIFT_BUNDLE = "SHIFT_BUNDLE";
    public static final String SHIFT_MODEL = "SHIFT_MODEL";
    public static final String SHIFT_NAME = "SHIFT_NAME";
    public static final String SHIFT_ID = "SHIFT_ID";
    private ArrayList<EmployeeListBean> list = new ArrayList<>();
    private CommonAdapter<EmployeeListBean> adapter;

    public static void actionStart(Context context,ArrayList<EmployeeListBean> list){
        Bundle bundle = new Bundle();
        bundle.putSerializable(SHIFT_MODEL, (Serializable) list);
        Intent intent = new Intent(context, ShiftManListActivity.class);
        intent.putExtras(bundle);
        ((ShiftActivity)context).startActivityForResult(intent,701);

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_type_company1);
        ButterKnife.bind(this);
        new TitleBuilder(this).setLeftImage(R.mipmap.ic_go_back)
                .setTitleText("交班人").setLeftImage(R.mipmap.ic_go_back)
                .setLeftOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        finish();
                    }
                });
        list.clear();
        EmployeeListBean employeeListBean = new EmployeeListBean();
        employeeListBean.setEmployee_name("无");
        employeeListBean.setId("0");
        list.add(employeeListBean);
        list.addAll((ArrayList<EmployeeListBean>) getIntent().getSerializableExtra(SHIFT_MODEL));

        initAdapter();
        initClick();
    }

    private void initAdapter() {
        adapter = new CommonAdapter<EmployeeListBean>(this,R.layout.item_list_company,list) {
            @Override
            protected void convert(ViewHolder viewHolder, EmployeeListBean item, int position) {
                viewHolder.setText(R.id.id_tv_company,item.getEmployee_name());
            }
        };
        idListview.setAdapter(adapter);
    }

    private void initClick() {
        idListview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent();
                intent.putExtra(SHIFT_NAME,list.get(position).getEmployee_name());
                intent.putExtra(SHIFT_ID,list.get(position).getId());
                setResult(RESULT_OK, intent);
                finish();
            }
        });
    }

}
